Repository navigation
Check calls on a constructor call whose constructor has refined parameters - #407
Open
CatarinaGamboa wants to merge 1 commit into
Open
CatarinaGamboa wants to merge 1 commit into
CatarinaGamboa wants to merge 1 commit into
Conversation
…eters A call made directly on new T(args), when T(args) has refined parameters, used the constructor's return-value instance (typed void) as its receiver, so the state ghost was applied to a void argument and verification failed with an Argument Mismatch Error. Check the constructor-call receiver before the TARGET metadata and reuse it across the invocation's checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #361 (typestate calls made directly on a constructor call).
Problem
A call made directly on
new T(args)fails when the constructorT(args)has refined parameters:With refined parameters, the constructor call goes through
applyReturnRefinement, which sets the call'sTARGETmetadata to the constructor's return-value instance (#<init>_N, typedvoid).prepareInvocationTargetcheckedTARGETbefore the constructor-call case, so it used that instance as the receiver. Constructors without refined parameters (new ServerSocket().accept()) were not affected.Fix
prepareInvocationTargethandles a constructor-call target before falling back toTARGETmetadata.Keys.RECEIVERkey on the constructor call and reused when the same invocation is prepared again (the target is prepared both for the parameter checks and for the state change), so it is created once.Tests
CorrectConstructorReceiverRefinedArgument:new Listener(8080).accept()whereListener(int)has a refined parameter and lands inbound. It failed before this change.ErrorConstructorReceiverRefinedArgument: the same constructor followed by a call that needsunboundis reported.mvn test: 414 tests, 0 failures.Found on a real fixed bug (a static page server whose fix was
new ServerSocket(port).accept()). We also checked 53 exercises built from real OSS bugs: the results are identical to main's.🤖 Generated with Claude Code